import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import { fetchHomeBannersAction, getBanners } from '../store/features/home'
import axios from 'axios'

export class Home extends PureComponent {
  componentDidMount() {
    // axios.get("http://codercba.com:1888/api/home/hotSuggests").then(res => {
    //   const list = res.data.data.map(item => item.tagText.text)
    //   this.props.getBanners(list)
    // })
    this.props.fetchHomeBanners()
  }

  render() {
    const { count } = this.props
    return (
      <div>
        home count: { count }
      </div>
    )
  }
}

const mapStateToProps = (state) => ({
  count: state.count.count,
  banners: state.home.banners
})

const mapDispatchToProps = (dispatch) => ({
  getBanners(list) {
    dispatch(getBanners(list))
  },
  fetchHomeBanners() {
    dispatch(fetchHomeBannersAction())
  }
})

export default connect(mapStateToProps, mapDispatchToProps)(Home)